package one.one.twentyThree;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class BinarySearchRecursionWhite {

	static int binarySearchRec(int k, int[] a, int l, int h) {
		System.out.println("low:" + l + ",high:" + h);
		if (l > h)
			return -1;

		int mid = l + (h - l) / 2;
		if (k < a[mid])
			return binarySearchRec(k, a, l, mid - 1);
		else if (k > a[mid])
			return binarySearchRec(k, a, mid + 1, h);
		else
			return mid;
	}

	static int binarySearch(int k, int[] a) {
		return binarySearchRec(k, a, 0, a.length - 1);
	}

	static void white(int[] l, int[] w, boolean p) {
		int r = -1;
		for (int i = 0; i < l.length; i++) {
			r = binarySearch(l[i], w);
			if (p && r != -1)
				System.out.println(l[i]);
			if (!p && r == -1)
				System.out.println(l[i]);
		}
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		List<Integer> list = new ArrayList<Integer>();
		System.out.println("List:");
		String l = scanner.nextLine();
		while (!l.equals("end")) {
			list.add(Integer.parseInt(l));
			l = scanner.nextLine();
		}
		Integer[] la = new Integer[list.size()];
		la = list.toArray(la);

		List<Integer> white = new ArrayList<Integer>();
		System.out.println("White:");
		String wl = scanner.nextLine();
		while (!wl.equals("end")) {
			white.add(Integer.parseInt(wl));
			wl = scanner.nextLine();
		}
		Integer[] w = new Integer[white.size()];
		w = white.toArray(w);

		
		
		String plusMinus = scanner.nextLine();
		scanner.close();


		System.out.println("List:" + Arrays.toString(la));
		System.out.println("White:" + Arrays.toString(w));
		
		boolean p = false;
		if (plusMinus.equals("-")) {
			p = true;
		}

		int[] lap=new int[la.length];
		for(int i=0;i<la.length;i++) {
			lap[i]=la[i];
		}

		int[] wp=new int[w.length];
		for(int i=0;i<w.length;i++) {
			wp[i]=w[i];
		}

		
		white(lap, wp, p);
	}

}
